/*
	Written By Pradipna Nepal
	www.pradsprojects.com

	Copyright (C) 2011 Prads Projects
	Please read COPYING.txt included along with this source code for more detail.
	If not included, see http://www.gnu.org/licenses/
*/

#include "libEmulator.h"

CPUCore *cpu = 0;
bool startEmulation = false;
HWND hwndDebug;	//Debugger HWND

BOOL CALLBACK Emulator::emuWndProc(HWND hwnd, UINT msG, WPARAM wParam, LPARAM lParam) {
	switch (msG) {
		case WM_KEYDOWN:
			{
				if (lParam & 0x40000000) break;
				Inputs *inputs = cpu->getInput();
				inputs->keyDown(&wParam);
			}
			break;
		case WM_KEYUP:
			{
				Inputs *inputs = cpu->getInput();
				inputs->keyUp(&wParam);
			}
			break;
		case WM_CLOSE:
			startEmulation = false;
			DEL_PTR(cpu);
			SendMessage(hwndDebug, WM_CLOSE, 0, 0);
			ShowWindow(hwnd, SW_HIDE);
			break;
		default:
			return FALSE;
	}
	return TRUE;
}

void Emulator::sendInitMessageToDebugger() {
	SendMessage(hwndDebug, WM_COMMAND, (WPARAM)DEBUGGER_COMMAND_INITIALIZE, 0);
}